package stage1.module2;

public class Homework1 {
    public static void main(String[] args) {
        //定义一个16*16的整型数组并赋值,值为行索引+列索引
        int[][] arr = new int[16][16];
        for(int i = 0; i < arr.length; i++){
            for(int j = 0; j < arr[0].length; j++){
                arr[i][j] = i + j;
            }
        }

        //打印各行元素和
        for(int i = 0; i < arr.length; i++){
            int row_sum = 0;
            //对所在行元素进行求和
            for(int j : arr[i]){
                row_sum += j;
            }
            System.out.println("第" + i + "行的元素和为：" + row_sum);
        }
        //打印各列元素和
        for(int j = 0; j < arr[0].length; j++){
            int column_sum = 0;
            //对所在列元素进行求和
            for(int[] i : arr){
                column_sum += i[j];
            }
            System.out.println("第" + j + "列的元素和为：" + column_sum);
        }
        //打印左上角到右下角元素和
        int sum1 = 0;
        for(int i = 0; i < arr.length; i++){
            sum1 += arr[i][i];
        }
        System.out.println("左上角到右下角元素和为:" + sum1);
        //打印右上角到左下角元素和
        int sum2 = 0;
        for(int i = 0; i < arr.length; i++){
            sum2 += arr[0][arr[i].length - 1 - i];
        }
        System.out.println("右上角到左下角元素和为:" + sum1);
    }
}
